/*************************************************************************
 * File Name:    1149.cc
 * Author:       zero91
 * Mail:         jianzhang9102@gmail.com
 * Created Time: Sun 20 Oct 2013 09:35:42 PM CST
 * 
 * Description:  http://poj.org/problem?id=1149
 ************************************************************************/

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <iomanip>

using namespace std;

#ifdef INFINITY
#undef INFINITY
#endif
#define INFINITY 0x3fffffff
#define MAXM 1010
#define MAXN 110
#define MAX_FLOW_CAP 0x1ffffff

int cap[MAXM][MAXM];

int
bfs(int src, int target, int *pre)
{
    queue<int> Q;
    int flow[target + 1], visited[target + 1];
    int v;

    for (int i = src; i <= target; ++i) {
        flow[i] = INFINITY;
        visited[i] = false;
    }
    Q.push(src);
    pre[src] = src;
    visited[src] = true;
    while (!Q.empty()) {
        v = Q.front(), Q.pop();
        if (v == target) break;

        for (int i = src; i <= target; ++i) {
            if (visited[i] || cap[v][i] == 0) continue;
            visited[i] = true;
            pre[i] = v;
            flow[i] = min(cap[v][i], flow[v]);
            Q.push(i);
        }
    }
    if (flow[target] == INFINITY) return 0;
    return flow[target];
}

int
maxflow(int src, int target)
{
    int sum = 0;
    int aug;
    int pre[target + 1];

    while ((aug = bfs(src, target, pre)) > 0) {
        sum += aug;
        for (int t = target; pre[t] != t; t = pre[t]) {
            cap[pre[t]][t] -= aug;
            cap[t][pre[t]] += aug;
        }
    }
    return sum;
}

int
main(int argc, char *argv[])
{
    int M, N, a, t;
    int src, target;
    int pigs[MAXM], last_user[MAXM];

    memset(cap, 0, sizeof(cap));
    memset(last_user, -1, sizeof(last_user));

    scanf("%d %d", &M, &N);
    for (int i = 1; i <= M; ++i) {
        scanf("%d", &pigs[i]);
    }
    src = 0, target = N + 1;
    for (int i = 1; i <= N; ++i) {
        scanf("%d", &a);
        for (int j = 0; j < a; ++j) {
            scanf("%d", &t);
            if (last_user[t] == -1) {
                cap[src][i] += pigs[t];
            } else {
                cap[last_user[t]][i] = MAX_FLOW_CAP;
            }
            last_user[t] = i;
        }
        scanf("%d", &cap[i][target]);
    }
    printf("%d\n", maxflow(src, target));

    return 0;
}
